<?php
  /**
   * @author EVANDRO DE OLIVEIRA.
   * @category VIEW
   * @package VIEWS/SCRIPTS/PAISES.
   * @since 17/06/2012.
   * @last_update 17/06/2012.
   * @copyright 2012.
   * @version 1.0.
   *
   */
  $objCurrency = new Zend_Currency();
?>
<script type="text/javascript">
  $(function(){
    $('#idCurso').change(function(){
      var strUrl = '<?=$this->baseUrl?>/matriculas/load-modulos-ajax/idCurso/' + $(this).val();
      $('#listaModulos').load(strUrl);                    
    });

    $('.parcelas').click(function(){
    	var strUrl = '<?=$this->baseUrl?>/matriculas/load-parcelas-ajax/idParcela/' + $(this).val();
    	$('#listaParcelas').load(strUrl);  
    });
  });
</script>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="content-view" id="teste">
  <tr>
    <td id="messenger" colspan="2"><?php echo $this->flashMessage();?></td>
  </tr>
  <tr>
    <td align="left" class="comp-title" style="width: 200px; text-transform: uppercase;">Edição de Aluno</td>  
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="center" colspan="2" style="">
      <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%" class="content-form">
        <tr>
          <td class="space-bottom"></td>
        </tr>
        <tr>
          <td>
            <form name="form_add" method="post" action="" id="form_add">
              <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td align="left" class="title-dp">dados pessoais</td> 
                  <td>&nbsp;</td> 
                </tr>
                <tr>
                  <td class="content-dp" colspan="2">
                    <table border="0" cellpadding="0" cellspacing="0">
                      <?php   
                        foreach($this->arrColunas as $strKey => $arrValues){
                        	//Zend_Debug::dump($arrValues['name']);
                            switch($arrValues['type']){
                              case 'text':
                              	if($arrValues['name'] != 'ds_matricula')
                                  $boolEnabled = true;
                                else
                                  $boolEnabled = false;                                                                  	 
                                $strCampo = $this->input($arrValues['type'], $arrValues['name'], $arrValues['name'], $this->request[$arrValues['name']], $boolEnabled, '', $arrValues['maxlength'], '', "width: {$arrValues['width']}px;");
                              break;
                              
                              case 'db_combo':
                                $strCampo = $this->dbComboBox($arrValues['name'], $arrValues['name'], $arrValues['model'], $arrValues['value'], $arrValues['label'], isset($this->request[$arrValues['value']]) ? $this->request[$arrValues['value']] : '', isset($this->request[$arrValues['label']]) ? $this->request[$arrValues['label']] : 'Selecione', true);
                              break;
        
                              case 'combo':
                                //$strCampo = $this->comboBox($arrValues['name'], $arrValues['name'], $arrValues['options'], $this->request[$arrValues['name']], false);
                                $strCampo = $this->comboBox($arrValues['name'], $arrValues['name'], $arrValues['options'], !empty($arrValues['name']) ? $this->request[$arrValues['name']] : 'Selecione', true);
                              break;
                              
                              case 'date':
                              case 'datetime':
                                $arrDataValue =  explode(" ", $this->request[$arrValues['name']]);                        
                                $strDate = $arrValues['default_value'] ? $arrValues['default_value'] : implode('/', array_reverse(explode('-', $arrDataValue[0])));
                                $strCampo = $this->input('text', $arrValues['name'], $arrValues['name'] , $strDate, false, '', '', $arrValues['maxlength'], "width: {$arrValues['width']}px;");
                              break;
                            }
                            ?>
                            <tr>    
                              <td align="right" class="label">
                                <?php 
                                  echo $arrValues['notnull'] ? '<span style="color: #FF0000; font-weight: bold"> * </span>' . $strKey : $strKey;
                                ?>:
                              </td>  
                              <td align="left" class="space-bottom"><?php echo $strCampo;?></td>
                              <td><span>&nbsp;</span></td>                     
                            </tr>     
                            <?php
                          }
                        ?>
                      </table>
                  </td>
                </tr>
                <tr>  
                  <td align="center" colspan="3">&nbsp;</td>
                </tr>
              </table>
              
              <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td align="left" class="title-dp">Curso e Turma</td> 
                  <td>&nbsp;</td>  
                </tr>
                <tr>
                  <td class="content-dp" colspan="2">
                    <table border="0" cellpadding="0" cellspacing="0">
                      <?php   
                        foreach($this->arrColunas2 as $strKey => $arrValues){
                          switch($arrValues['type']){
                          	case 'db_combo':
                          		$strCampo = $this->dbComboBox($arrValues['name'], $arrValues['name'], $arrValues['model'], $arrValues['value'], $arrValues['label'], isset($this->request[$arrValues['value']]) ? $this->request[$arrValues['value']] : '', isset($this->request[$arrValues['label']]) ? $this->request[$arrValues['label']] : 'Selecione', true);
                            break;
                            case 'combo':
                            	$strCampo = $this->comboBox($arrValues['name'], $arrValues['name'], $arrValues['options'], !empty($arrValues['name']) ? $this->request[$arrValues['name']] : 'Selecione', true);
                            break;
                          }
                          ?>
                          <tr>    
                            <td align="right" class="label">
                              <?php 
                                echo $arrValues['notnull'] ? '<span style="color: #FF0000; font-weight: bold"> * </span>' . $strKey : $strKey;
                              ?>:
                            </td>  
                            <td align="left" class="space-bottom">
                              <?php
		                            if($arrValues['name'] == 'idModulo'){?>
		                              <div id="listaModulos"><?php  echo $strCampo?></div>
		                              <?php 
		                            }
		                            elseif($arrValues['name'] == 'idTurma'){?>
		                              <div id="listaTurmas"><?php  echo $strCampo?></div>
		                              <?php 
		                            } 
		                            else{
		                              echo $strCampo;
		                            }
		                          ?>
                            </td>
                            <td><span>&nbsp;</span></td>                     
                          </tr>     
                          <?php
                        }
                      ?>
                    </table>
                  </td>
                </tr>
                <tr>  
                  <td align="center" colspan="3">&nbsp;</td>
                </tr>
              </table>
              
              <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td align="left" class="title-dp">Preço e Opção de Parcelamento</td> 
                  <td>&nbsp;</td>  
                </tr>
                <tr>
                  <td class="content-dp" colspan="2">
                    <div id="showValores">
                      <table border="0" cellpadding="0" cellspacing="0" width="100%">
	                      <?php   
	                        foreach($this->arrColunas3 as $strKey => $arrValues){
	                        	switch($arrValues['type']){
	                        		case 'text':
	                        			$strCampo = $this->input($arrValues['type'], $arrValues['name'], $arrValues['name'], $objCurrency->setValue($this->request[$arrValues['name']]), true, '', $arrValues['maxlength'], '', "width: {$arrValues['width']}px;");
	                            break;
	                          }
	                          ?>  
	                          <tr>
	                            <td align="right" class="label" style="width: 15%"><?php echo $strKey?>:</td>  
	                            <td align="left" class="space-bottom"><?php echo $strCampo?></td>                      
	                          </tr>
	                          <?php
	                        }
	                      ?>
	                      <tr>  
	                        <td align="center" colspan="2">&nbsp;</td>
	                      </tr>
                        
                        <tr>
                          <td colspan="2">
                            <table border="0" align="center" cellpadding="0" cellspacing="0" width="70%">
	                            <thead> 
	                              <tr> 
	                                <th class="title-list" style="width: 7%"></th> 
	                                <th class="title-list">Condição</th> 
	                                <th class="title-list">Valor</th>  
	                              </tr> 
	                            </thead> 
                              <tbody>
	                              <?php
                                  $intCounter = count($this->arrContasReceber);
                                  $arrUltimaParcela = end($this->arrContasReceber);
	                                foreach($this->arrParcelas as $strParcela => $strValor){
                                    if($strParcela == $arrUltimaParcela['nr_parcela']){
                                    	$strCorLinha = 'background-color: #DFF2BF;';
                                    	$strChecked = 'checked="checked"';
                                    }
                                    else{
                                    	$strCorLinha = '';
                                      $strChecked = '';
	                                	}
	                                	?>
		                                <tr>
				                              <td class="result-list" style="<?php echo $strCorLinha?>">
				                                <input type="radio" name="ds_parcela" id="ds_parcela" class="parcelas" <?php echo $strChecked?> value="<?php echo $strParcela?>_<?php echo $strValor?>_<?php echo $this->intIdModulo?>"/>
				                              </td>
				                              <td class="result-list" style="text-align: left; <?php echo $strCorLinha?>">
				                                <?php 
				                                  if($strParcela == 1){
				                                    echo 'À VISTA';
				                                  }   
				                                  else{
				                                    echo $strParcela . 'X';
				                                  }
				                                ?>
				                              </td>
				                              <td class="result-list" style="<?php echo $strCorLinha?>">
				                                <?php echo $objCurrency->setValue($strValor);?>
				                              </td>
				                            </tr>
		                                <?php 
	                                }
	                              ?>    
                              </tbody>
                            </table>
                          </td>
                        </tr>
                      </table>
                    </div>  
                  </td>
                </tr>
                <tr>  
                  <td align="center" colspan="3">&nbsp;</td>
                </tr>
              </table>
              
              <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td align="left" class="title-dp">Contrato</td> 
                  <td>&nbsp;</td>  
                </tr>
                <tr>
                  <td class="content-dp" colspan="2">
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                      <?php   
                        foreach($this->arrColunas4 as $strKey => $arrValues){
                        	//Zend_Debug::dump($this->request[$arrValues['name']]);
                          switch($arrValues['type']){
                            case 'checkbox':
                              $boolChecked = false;
                              if($this->request[$arrValues['name']] == '1')
                                $boolChecked = true;     
                                                         
                              $strCampo = $this->input($arrValues['type'], $arrValues['name'], $arrValues['name'], $this->request[$arrValues['name']], true, '', '', '', '', '', $boolChecked);
                            break;
                          }
                          ?>  
                          <tr>
                            <td align="right" class="label" style="width: 20%"><?php echo $strKey?>:</td>  
                            <td align="left" class="space-bottom" style="padding-top: 8px;">
                              <?php echo $strCampo?> 
                              <span style="float: right;">
                                <a href="<?php echo $this->baseUrlController?>/contrato/cod/<?php echo $this->request['idAluno']?>" target="blank" style="text-decoration: none; font-weight: bold; font-size: 12px; color: #344796;">
                                  Visualizar Contrato
                                </a>
                              </span>
                            </td>                      
                          </tr>
                          <?php
                        }
                      ?>
                      <tr>
                        <td colspan="2">&nbsp;</td>
                      </tr>
                    </table>
                  </td>
                </tr>
                <tr>  
                  <td align="center" colspan="3">&nbsp;</td>
                </tr>
              </table>        
              
              <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td align="left" class="title-dp">Parcelas</td> 
                  <td>&nbsp;</td>  
                </tr>
                <tr>
                  <td class="content-dp" colspan="2">
                    <div id="listaParcelas">
	                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
	                      <thead> 
	                        <tr> 
	                          <th class="title-list" style="width: 7%"></th> 
	                          <th class="title-list">Parcela</th> 
	                          <th class="title-list">Valor</th>
	                          <th class="title-list">Vencimento</th>
	                          <th class="title-list"></th>  
	                        </tr> 
	                      </thead> 
	                      <tbody>
	                        <?php 
	                          foreach($this->arrContasReceber as $arrContasReceber){
                              //Zend_Debug::dump($arrContasReceber);
                              ?>
                              <tr>
                                <td class="result-list"></td>
                                <td class="result-list" style="text-align: left;">
                                  Parcela <?php echo $arrContasReceber['nr_parcela']?>
                                </td>
                                <td class="result-list">
                                  <?php echo $objCurrency->setValue($arrContasReceber['nr_valor']);?>
		                            </td>
		                            <td class="result-list">
		                              <?php echo implode('/', array_reverse(explode('-', $arrContasReceber['dt_vencimento'])));?>
		                            </td>
		                            <td class="result-list">
		                              <?php 
                                    echo $this->input('hidden', 'idParcela_' . $arrContasReceber['nr_parcela'], 'idParcela_' . $arrContasReceber['nr_parcela'], $arrContasReceber['nr_parcela'], true);
                                    echo $this->input('hidden', 'ds_valor_' . $arrContasReceber['nr_parcela'], 'ds_valor_' . $arrContasReceber['nr_parcela'], $arrContasReceber['nr_valor'], true);
                                    echo $this->input('hidden', 'dt_vencimento_' . $arrContasReceber['nr_parcela'], 'dt_vencimento_' . $arrContasReceber['nr_parcela'], $arrContasReceber['dt_vencimento'], true);
                                  ?>
		                            </td>
		                          </tr>
		                          <?php
		                        }
		                      ?>  
	                      </tbody>
	                    </table>
	                  </div>  
                  </td>
                </tr>
              </table>        
              <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
                <tr>  
                  <td align="center" colspan="3">&nbsp;</td>
                </tr>
                <tr> 
                  <td align="right">
                    <?php 
                      echo $this->input('submit', 'save', 'boton', 'Salvar', true);
                    ?>
                  </td> 
                  <td>
                    <span>&nbsp;</span>
                    <?php 
                      echo $this->input('hidden', 'idAluno', 'idAluno', $this->intAluno, true);
                    ?>
                  </td>
                  <td align="left">
                    <?php 
                      echo $this->input('button', 'cancel', 'boton', 'Cancelar', true, '', '', '', '', "onclick=\"window.location='" . $this->baseUrl . "/matriculas/list'\"");
                    ?>
                  </td>
                </tr>
              </table>
            </form>
          </td>
        </tr>
      </table>
    </td>
  </tr>  
</table>